<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>典型案例类型管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
    <script type="text/javascript" src="/layuicms/layui/layui.js"></script>
    <style type="text/css">
        .ke-container.ke-container-default{
            width: 100% !important;
        }
    </style>
</head>

<body>
<!-- 添加和修改的弹出层开始 -->
<div style="padding: 5px 20px 0 0" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">警示类型</label>
                <div class="layui-input-inline">
                    <select name="safetyId" id="safetyId" lay-verify="required" class="search_safety"  lay-filter="safetyId">
                        <option value="">请选择警示类型</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">文件夹</label>
                <div class="layui-input-inline">
                    <select name="coreId" id="coreId" lay-verify="required"   lay-filter="fileType">
                        <option value="">请选择文件夹</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">案例标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id">
                <input type="text" style="width: 515px" name="classicTitle" lay-verify="required" lay-reqtext="案例标题是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件类型</label>
            <div class="layui-input-block">
                <input type="radio" name="fileType" lay-filter="fileType" value="1" title="PPT" checked="">
                <input type="radio" name="fileType" lay-filter="fileType" value="2" title="视频">
                <span class="layui-inline" style="color: red;margin-top: 10px;">* 请正确选择文件类型 .默认为PPT*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-upload">
                <label class="layui-form-label">附件</label>
                <input type="hidden" name="caseImage" id="caseImage">
                <button type="button" class="layui-btn layui-btn-sm" id="caseFile"><i class="layui-icon"></i>    选择文件</button>
                <span class="layui-inline" style="color: gray" id="fileName"></span>
            </div>
            <!--<label class="layui-form-label">附件</label>
            <div class="layui-input-block layui-upload">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="AAAA">选择文件</button>
                    <div class="layui-upload-list">
                        <table class="layui-table" style="width: 515px">
                            <thead>
                            <th>文件名</th>
                            <th>大小</th>
                            <th>状态</th>
                            <th>操作</th>
                            </thead>
                            <tbody id="demoListss"></tbody>
                        </table>
                    </div>
                    <button type="button" class="layui-btn layui-btn-sm" id="testListAction">开始上传</button>
                </div>
            </div>
            <input type="hidden" name="info" id="info">-->
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">是否可用</label>
                <div class="layui-input-inline">
                    <input type="radio" name="available"  value="1" title="可用" checked="">
                    <input type="radio" name="available" value="0" title="不可用" >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">排序码</label>
                <div class="layui-input-block">
                    <input type="text" id="ordernum" name="ordernum" lay-verify="required|number" autocomplete="off" placeholder="请输入排序码[>0]" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->
</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['upload','jquery','form','table','layer',],function(){
        var $ = layui.jquery;
        var form=layui.form;
        var layer = layui.layer,upload = layui.upload;
        $.get("/caseClassic/loadCaseClassicMaxOrderNum",function (res) {
            $("#ordernum").val(res.value);
        });
        //模糊查询
        //加载查询条件安全预警类型的下拉列表
        $.get("/safetyAlertType/loadAllsafetyAlertTypeForSelect",function(res){
            var data=res.data;
            var dom=$(".search_safety");
            var html='<option value="">请选择警示类型</option>'
            $.each(data,function(index,item){
                html+='<option value="'+item.id+'">'+item.typename+'</option>'
            });
            dom.html(html);
            form.render("select");
        });

        //监听添加页面供应商下拉框的改变事件
        form.on('select(safetyId)',function (data) {
            var safetyId = data.value;
            initfileSelect(safetyId);
        })
        //加载添加文件夹
        function initfileSelect(safetyId,goodsid) {
            $.get("/coreType/loadBySafetyTypeForSelect",{safetyId:safetyId},function(res){
                var data=res.data;
                var dom=$("#coreId");
                var html='<option value="">请选择文件夹</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.typename+'</option>'
                });
                dom.html(html);
                //如果goodsid有值就反选
                if (goodsid!=undefined){
                    dom.val(goodsid);
                }
                form.render("select");
            });
        }
        //添加和修改的提交
        form.on("submit(doSubmit)",function (data) {
            var caseImae= $("#caseImage").val();
            if(caseImae==""){
                layer.msg("请选择要上传的文件");
            }else{
                $.post("/caseClassic/addCaseClassic",data.field,function (res) {
                    if(res.code==20000){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    }
                    layer.msg(res.message);
                    parent.layer.close(index);
                })
            }
            return false
        });
        var exts ="";
        form.on('radio(fileType)', function(data){
            if(data.value==1||data.elem==1){
                exts = 'ppt|pptx';
            }else{
                exts = 'mp4';
            }
        });
        upload.render({
             elem: '#caseFile'
            ,url: '/file/uploadFild'
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
              layer.load(0); //上传loading
            }
            ,accept: 'file'
            ,exts: 'ppt|pptx|mp4|avi'
            ,field:'mf'
            ,done: function(res, index, upload){
                    var path = res.path;
                    var fileName = res.fileName;
                    $('.thumbImg').attr('src','/file/showImageByPath?path='+path);
                    $('.thumbBox').css("background","#fff");
                    $("#fileName").text(fileName);//给隐藏域赋值
                    $("#caseImage").val(path);//给隐藏域赋值
                    layer.closeAll('loading'); //关闭loading
                }
        });
     /*   var url = "";// 访问路径
        var demoListView = $('#demoListss')
            ,uploadListIns = upload.render({
            elem: '#AAAA'
            ,url: '/caseClassic/uploadFile'
            ,accept: 'file'
            ,exts: 'ppt|pptx'
            ,multiple: true
            ,auto: false
            ,bindAction: '#testListAction'
            ,choose: function(obj){
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function(index, file, result){
                    var tr = $(['<tr id="upload-'+ index +'">'
                        ,'<td>'+ file.name +'</td>'
                        ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                        ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                        ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function(){
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    demoListView.append(tr);
                });
            }
            ,done: function(res, index, upload){
                if(res.code == 0){ //上传成功
                    //拼接字符串后台返回的路径
                    uploadNa=uploadNa+res.msg+",";
                    $("#uploadname").val(uploadNa);
                    //alert(uploadNa);
                    var tr = demoListView.find('tr#upload-'+ index)
                        ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                    tds.eq(3).html(''); //清空操作
                    return delete this.files[index]; //删除文件队列已经上传成功的文件
                }
                this.error(index, upload);
            }
            ,error: function(index, upload){
                var tr = demoListView.find('tr#upload-'+ index)
                    ,tds = tr.children();
                tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
        });*/
    });
</script>
</html>